﻿using System;
using System.Collections.Generic;
namespace MutsiEngine
{
    public static class MutsiMath
    {
        public const double PI = 3.14159265;

        public static double Cotangent(double x)
        {
            return 1.0 / Math.Tan(x);
        }

        public static double DegreesToRadians(double Degrees)
        {
            return Degrees * (PI / 180.0);
        }

        public static double RadiansToDegrees(double Radians)
        {
            return 0;
            //TODO make the function
        }

        public static float[] Vector2ListToFloat(List<Vector2> list)
        {
            List<float> floatList = new List<float>();
            foreach (Vector2 vector in list)
            {
                floatList.Add(vector.X);
                floatList.Add(vector.Y);
            }
            return floatList.ToArray();
        }

        public static float[] Vector3ListToFloat(List<Vector3> list)
        {
            List<float> floatList = new List<float>();
            foreach (Vector3 vector in list)
            {
                floatList.Add(vector.X);
                floatList.Add(vector.Y);
                floatList.Add(vector.Z);
            }
            return floatList.ToArray();
        }


        public static T Clamp<T>(this T val, T min, T max) where T : IComparable<T>
        {
            if (val.CompareTo(min) < 0) return min;
            else if (val.CompareTo(max) > 0) return max;
            else return val;
        }

        public static Vector3 CalculateNormal(Vector3 vec1, Vector3 vec2, Vector3 vec3)
        {
            return Vector3.Normalize(Vector3.CrossProduct(vec2 - vec1, vec3 - vec1));
        }
    }
}
